<script setup>
import {
    Management,
    Promotion,
    UserFilled,
    User,
    Crop,
    EditPen,
    SwitchButton,
    CaretBottom,
Place,
Dish,
Calendar,
Coordinate,
DocumentRemove,
} from '@element-plus/icons-vue'
import avatar from '@/assets/default.png'
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { ElMessage } from 'element-plus';
import { ElMessageBox } from 'element-plus';
import { useUserStore } from '@/stores/token.js';


const router = useRouter()

const userStore = useUserStore();




// 处理下拉菜单命令
const handleCommand = async (key) => {
  if (key === 'logout') {
    // 退出操作
    await ElMessageBox.confirm('你确认要进行退出么', '温馨提示', {
      type: 'warning',
      confirmButtonText: '确认',
      cancelButtonText: '取消'
    })

     // 清除本地的数据 (token + user信息)
     userStore.removeToken(); // 清除 token
     userStore.setUser({}); // 清除用户信息，假设你有一个类似的函数来清除用户信息
    
    router.push('/login')
  } else {
    // 跳转操作
    router.push(`/user/${key}`)
  }
}
</script>

<template>
    <!-- element-plus中的容器 -->
    <el-container class="layout-container">
        <!-- 左侧菜单 -->
        <el-aside width="200px">
            <div class="el-aside__logo"></div>
            <!-- element-plus的菜单标签 -->
            <el-menu active-text-color="#ffd04b" background-color="#85C1E9"  text-color="#fff" 
                router >
                <el-sub-menu index="/admin/scenic/list">
                    <template #title>
                        <el-icon>
                            <Place />
                        </el-icon>
                        <span>景点</span>
                    </template>
                    <el-menu-item index="/admin/scenic/all">
                        <el-icon>
                            <Place />
                        </el-icon>
                        <span>全部景点</span>
                    </el-menu-item>
                    <el-menu-item index="/admin/scenic/list">
                        <el-icon>
                            <Coordinate />
                        </el-icon>
                        <span>热门景点</span>
                    </el-menu-item>
                </el-sub-menu>
                
                <el-menu-item index="/travel/foods/list">
                    <el-icon>
                        <Dish />
                    </el-icon>
                    <span>美食</span>
                </el-menu-item>
                <el-menu-item index="/travel/actives/list">
                    <el-icon>
                        <Calendar />
                    </el-icon>
                    <span>活动</span>
                </el-menu-item>
                <el-menu-item index="/travel/feedback">
                        <el-icon>
                            <DocumentRemove />
                        </el-icon>
                        <span>反馈</span>
                </el-menu-item>
                <el-sub-menu index="/personal-center">
                    <template #title>
                        <el-icon>
                            <UserFilled />
                        </el-icon>
                        <span>个人中心</span>
                    </template>
                    <el-menu-item index="/user/info">
                        <el-icon>
                            <User />
                        </el-icon>
                        <span>基本资料</span>
                    </el-menu-item>
                    <el-menu-item index="/user/avatar">
                        <el-icon>
                            <Crop />
                        </el-icon>
                        <span>更换头像</span>
                    </el-menu-item>
                    <el-menu-item index="/user/resetPassword">
                        <el-icon>
                            <EditPen />
                        </el-icon>
                        <span>重置密码</span>
                    </el-menu-item>
                </el-sub-menu>

                <el-sub-menu index="/business">
                    <template #title>
                        <el-icon>
                            <UserFilled />
                        </el-icon>
                        <span>用户管理</span>
                    </template>
                    <el-menu-item index="/upload">
                        <el-icon>
                            <User />
                        </el-icon>
                        <span>权限管理</span>
                    </el-menu-item>
                </el-sub-menu>
                
            </el-menu>
        </el-aside>
        <!-- 右侧主区域 -->
        <el-container>
            <!-- 头部区域 -->
            <el-header>
                <div>当前用户：<strong>超级管理员</strong></div>
                <!-- 下拉菜单 -->
                <el-dropdown placement="bottom-end" @command="handleCommand">
                    <span class="el-dropdown__box">
                        <el-avatar :src="avatar" />
                        <el-icon>
                            <CaretBottom />
                        </el-icon>
                    </span>
                    <template #dropdown>
                        <el-dropdown-menu>
                            <el-dropdown-item command="profile" :icon="User">基本资料</el-dropdown-item>
                            <el-dropdown-item command="avatar" :icon="Crop">更换头像</el-dropdown-item>
                            <el-dropdown-item command="password" :icon="EditPen">重置密码</el-dropdown-item>
                            <el-dropdown-item command="logout" :icon="SwitchButton">退出登录</el-dropdown-item>
                        </el-dropdown-menu>
                    </template>
                </el-dropdown>
            </el-header>
            <!-- 中间区域 -->
            <el-main>
                <!-- <div style="width: 1290px; height: 570px;border: 1px solid red;">
                    内容展示区
                </div> -->
                <router-view></router-view>
            </el-main>
            <!-- 底部区域 -->
            <el-footer></el-footer>
        </el-container>
    </el-container>
</template>

<style lang="scss" scoped>
.layout-container {
    height: 100vh;

    .el-aside {
        background-color: #85C1E9;

        &__logo {
            height: 120px;
            background: url('@/assets/logo.png') no-repeat center / 120px auto;
        }

        .el-menu {
            border-right: none;
        }
    }

    .el-header {
        background-color: #fff;
        display: flex;
        align-items: center;
        justify-content: space-between;

        .el-dropdown__box {
            display: flex;
            align-items: center;

            .el-icon {
                color: #999;
                margin-left: 10px;
            }

            &:active,
            &:focus {
                outline: none;
            }
        }
    }

    .el-footer {
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 14px;
        color: #666;
    }
}
</style>
